package com.boardgame.gwt.service.operate.action.advance;

import com.boardgame.common.entity.ResponseInfo;
import com.boardgame.gwt.data.GwtGameBoard;
import com.boardgame.gwt.data.GwtPlayerInfo;
import com.boardgame.gwt.finalinfo.SyntaxMatchFinal;
import com.boardgame.gwt.service.operate.SyntaxRequest;
import com.boardgame.gwt.service.operate.action.Initial.IndiansTradeAction;
import com.boardgame.gwt.service.operate.action.Initial.InitialAction;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 花2元推动火车2部
 */
public class AdvanceTrainCost2CoinAction extends InitialAction {
    @Override
    public Pattern getPattern() {
        return Pattern.compile(SyntaxMatchFinal.INITIAL_AdvanceTrainCost2_ACTION);
    }

    @Override
    public ResponseInfo action(GwtGameBoard gwtGameBoard, SyntaxRequest syntaxRequest, Matcher matcher) {
        super.action(gwtGameBoard, syntaxRequest, matcher);
        GwtPlayerInfo gwtPlayerInfo = this.gwtGameBoard.getCurrentPlayer();
        //判断是否大于2元
        if (gwtPlayerInfo.getCoins()<2){
            return ResponseInfo.Failed("你的金钱不足2元");
        }
        else{
            //扣钱
            gwtPlayerInfo.setCoins(gwtPlayerInfo.getCoins()-2);

        }
        return ResponseInfo.Success(null);
    }
    public static AdvanceTrainCost2CoinAction create(){
        return new AdvanceTrainCost2CoinAction();
    }
}
